﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using VIP;
using VIP.Extension;
using VIP.Manager;

public class HitPanel : BasePanel
{

    private Text contentText;
    private Text newContentText;

    /// <summary>
    /// 是否有Id(是否正在显示)
    /// </summary>
    private string id;

    /// <summary>
    /// 延时时长
    /// </summary>
    private float time = 2.0f;

    public override void Init(params object[] param)
    {
        base.Init(param);
        layer = PANEL_LAYER.Tip;
        id = null;
    }

    public override void OnShow()
    {
        base.OnShow();
        contentText = gameObject.FindChildByName("Content").GetComponent<Text>();
        newContentText = gameObject.FindChildByName("NewContent").GetComponent<Text>();
    }

    public override void OnClose()
    {
        base.OnClose();

    }

    /// <summary>
    /// 设置Text
    /// </summary>
    /// <param name="content">内容</param>
    /// <param name="time">延时时长</param>
    /// <param name="always">是否总是显示</param>
    /// <returns></returns>
    public HitPanel MakeText(string content, float time)
    {
        contentText.text = content;
        newContentText.text = content;
        this.time = time;
        return this;
    }

    /// <summary>
    /// 创建面板（这个用于Instantiate）
    /// </summary>
    public void Create()
    {
        transform.Reset();
        if (id.IsNotEmpty())
        {
            VIPDelay.Instance.RemoveDelay(id);
        }
        //销毁面板（这个用于Instantiate）
        id = VIPDelay.Instance.AddDelay(time, (data) =>
        {
            //关闭当前面板
            Close();
            id = null;
        });
    }

}